<template>
  <page-header-wrapper>
    <a-card :bordered="false">
      <div class="table-page-search-wrapper">
        <a-form layout="inline">
          <a-row :gutter="24">
            <a-col :md="4" :sm="24">
              <a-form-item>
                <a-input placeholder="请输入活动名称" v-model="queryParam.name" />
              </a-form-item>
            </a-col>
            <a-col :md="4" :sm="24">
              <span class="table-page-search-submitButtons">
                <a-button type="primary" @click="handleSearch(true)" icon="search">查询</a-button>
              </span>
            </a-col>
          </a-row>
        </a-form>
      </div>
      <s-table
        ref="table"
        size="default"
        rowKey="id"
        :columns="columns"
        :data="loadData"
        :showPagination="false"
      >
        <template slot="status" slot-scope="status">
          <a-tag :color="kindsStatusDisplay(status)">{{ status | kindsStatusFilter }}</a-tag>
        </template>
        <a-badge :status="runTimeStatus(text)" :text="runTimeDisplay(text)" slot="runtime" slot-scope="text" />
        <span slot="action" slot-scope="text, record">
          <template>
            <a @click="$refs.douyinConvert.show();name=record.name;activity_id=record.id">选择兑换</a>
          </template>
        </span>
      </s-table>
    </a-card>

    <douyin-convert ref="douyinConvert" @change="change" :activity_id="activity_id" :encrypted_data="encrypted_data" :name="name"/>
  </page-header-wrapper>
</template>

<script>
import { clothesDouyinList,clothesDouyinConvert } from '@/api/clothes'
import orderStatus from '@/mixins/orderStatus'
import formTableMixin from '@/mixins/formTableMixin'
import runtimeStatus from '@/mixins/runtimeStatus'
import douyinConvert from './modules/douyinConvert'
import {applianceDownfall, appliancePutaway} from "@/api/appliance";
import DouyinConvert from "@/views/clothes/modules/douyinConvert";
import {mapGetters} from "vuex";

const columns = [
  {
    title: '活动名称',
    dataIndex: 'name'
  },
  {
    title: '价格',
    dataIndex: 'price',
    customRender (text) {
      return '￥' + text
    }
  },
  {
    title: '数量',
    dataIndex: 'number',
    width: 90
  },
  {
    title: '内容',
    dataIndex: 'content',
    width: 500
  },
  {
    title: '开始时间',
    dataIndex: 'atime',
    width: 120
  },
  {
    title: '结束时间',
    dataIndex: 'etime',
    width: 120
  },
  {
    title: '权重',
    dataIndex: 'weight',
    width: 90
  },
  {
    title: '状态',
    dataIndex: 'runtime',
    scopedSlots: { customRender: 'runtime' }
  },
  {
    title: '是否上架',
    dataIndex: 'status',
    scopedSlots: { customRender: 'status' },
    width: 100
  },
  {
    title: '操作',
    dataIndex: 'action',
    width: '200px',
    scopedSlots: { customRender: 'action' }
  }
]

export default {
  name: 'clothesDouyinList',
  components: { douyinConvert },
  mixins: [orderStatus, formTableMixin, runtimeStatus],
  data () {
    this.columns = columns;
    return {
      activity_id: '',
      //verify_id: '',
      encrypted_data: '',
      name: '',
    }
  },
  created() {
    //console.log(this.$route.query.verify_id&&this.$route.query.price,1122222222222222)
    if(this.$route.query.encrypted_data!=null&&this.$route.query.price!=null){
      //this.verify_id = this.$route.query.verify_id;
      this.encrypted_data = this.$route.query.encrypted_data;
      this.listAction = parameter =>
        clothesDouyinList({
          price: this.$route.query.price
        }).then(res => {
          const data = res.data
          data.forEach(item => {
            const status = this.getRunTime(item.atime, item.etime)
            item.runtime = status
          })
          res.data.data = res.data;
          return res
        })
    }else{
      this.$message.warn(this.userInfo.type==1 ? '请使用门店管理员操作' : '抖音订单核销时进入此页面')
    }
  },
  computed: {
    ...mapGetters(['userInfo'])
  },
  methods: {
    change(){
      setTimeout(()=>{
        this.$router.go(-1)
      },1000)
    },
    select(id){
      this.$confirm({
        title: '兑换确认',
        content: '你确定选择此活动吗?',
        onOk: () => {
          clothesDouyinConvert({
            activity_id: id,
            verify_id: Number(this.$route.query.verify_id)
          }).then(res => {
            this.$message.success('操作成功');
            setTimeout(()=>{
              this.$router.go(-1)
            },1000)
          })
        }
      })
    }
  }
}
</script>
